
We know class is a blue print of object. When we create a class then it can be containing many properties. We can use this class property by the create the object of this class. Also reuse the code by the create object. Now given bellow the code and explanation of this code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ObjectTest
{
internal class Students
{
public int ID { get; set; }
public string Name { get; set; }
public int AccountId { get; set; }
public string Email { get; set; }
}
class Program
{
static void Main(string[] args)
{
//Create an object and initialize the constructor by the new keyword.
Students obj = new Students();
obj.ID = 10;
obj.Name="Farhan Sakib";
obj.AccountId = 201515;
obj.Email = "fsjesy@gmail.com";
//print the value of the class.
Console.WriteLine("Your Name :"+ obj.Name);
Console.WriteLine("Your Email : " + obj.Email);
Console.ReadKey();
}
}
}
We can see the student class this class contain many property’s like Id, Name, AccountId, Email. Now under Main method create an object of the student class and also initialize the Constructor by the new key word. Now we access object property by “.”. First, we assign every fields value of the student class and then print the two fields by the Console.WriteLine Function. We can see the output like this: